package com.yanqu.road.entity.activity.harps;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class HarpsParamConfig {

    // 音律积分
    private int scoreItem;

    // 桑蚕丝
    private int mountainItemId;

    // 使用一个蚕丝弦获取的积分
    private int mountainScoreGain;

    // 对应楼层|不动概率|上升概率|下降概率(千分比);  1=底层，4=顶层
    private List<List<Integer>> mountainFloorPro;

    // 对应楼层|透明气泡数量|金色气泡数量|粉色气泡数量;  1=底层，顶层无气泡
    private List<List<Integer>> mountainColorNum;

    // 连续消耗n个蚕丝弦没有登顶，则上升概率调整为100%，持续到登顶，登顶之后清空计数
    private int mountainMaxDraw;

    // 轮次;消耗|轮次;消耗|轮次;消耗（轮次即抽了几次大奖）
    private List<List<Integer>> mountainDrawNum;

    // 十连限制积分数量
    private int mountainTenPlayLimit;


    public boolean initParamConfig(Map<String, ActivityConfig> activityConfigMap) {
        setScoreItem(activityConfigMap.get(eActivityConfigType.EXCHANGE_SCORE_ITEM_ID_HARPS.getName()).getIntValue());
        setMountainItemId(activityConfigMap.get(eActivityConfigType.MOUNTAIN_ITEM_ID.getName()).getIntValue());
        setMountainScoreGain(activityConfigMap.get(eActivityConfigType.MOUNTAIN_SCORE_GAIN.getName()).getIntValue());
        setMountainFloorPro(parseIntSep(activityConfigMap.get(eActivityConfigType.MOUNTAIN_FLOOR_PRO.getName()).getValue(), ";", "\\|"));
        setMountainColorNum(parseIntSep(activityConfigMap.get(eActivityConfigType.MOUNTAIN_COLOR_NUM.getName()).getValue(), ";", "\\|"));
        setMountainMaxDraw(activityConfigMap.get(eActivityConfigType.MOUNTAIN_MAX_DRAW.getName()).getIntValue());
        setMountainDrawNum(parseIntSep(activityConfigMap.get(eActivityConfigType.MOUNTAIN_DRAW_NUM.getName()).getValue(), "\\|", ";"));
        setMountainTenPlayLimit(activityConfigMap.get(eActivityConfigType.MOUNTAIN_TENPLAY_LIMIT.getName()).getIntValue());
        return true;
    }

    private List<List<Integer>> parseInt(String str) {
        List<List<Integer>> result = new ArrayList<>();
        List<String> paramList = StringUtils.stringToStringList(str, "\\|");
        for (String param : paramList) {
            List<Integer> list = StringUtils.stringToIntegerList(param, ";");
            result.add(list);
        }
        return result;
    }

    private List<List<Integer>> parseIntSep(String str, String seq1, String seq2) {
        List<List<Integer>> result = new ArrayList<>();
        List<String> paramList = StringUtils.stringToStringList(str, seq1);
        for (String param : paramList) {
            List<Integer> list = StringUtils.stringToIntegerList(param, seq2);
            result.add(list);
        }
        return result;
    }

    private List<List<Long>> parseLong(String str) {
        List<List<Long>> result = new ArrayList<>();
        List<String> paramList = StringUtils.stringToStringList(str, "\\|");
        for (String param : paramList) {
            List<Long> list = StringUtils.stringToLongList(param, ";");
            result.add(list);
        }
        return result;
    }

    public int getScoreItem() {
        return scoreItem;
    }

    public void setScoreItem(int scoreItem) {
        this.scoreItem = scoreItem;
    }

    public int getMountainItemId() {
        return mountainItemId;
    }

    public void setMountainItemId(int mountainItemId) {
        this.mountainItemId = mountainItemId;
    }

    public int getMountainScoreGain() {
        return mountainScoreGain;
    }

    public void setMountainScoreGain(int mountainScoreGain) {
        this.mountainScoreGain = mountainScoreGain;
    }

    public int getMountainMaxDraw() {
        return mountainMaxDraw;
    }

    public void setMountainMaxDraw(int mountainMaxDraw) {
        this.mountainMaxDraw = mountainMaxDraw;
    }

    public int getMountainTenPlayLimit() {
        return mountainTenPlayLimit;
    }

    public void setMountainTenPlayLimit(int mountainTenPlayLimit) {
        this.mountainTenPlayLimit = mountainTenPlayLimit;
    }

    public List<List<Integer>> getMountainFloorPro() {
        return mountainFloorPro;
    }

    public void setMountainFloorPro(List<List<Integer>> mountainFloorPro) {
        this.mountainFloorPro = mountainFloorPro;
    }

    public List<List<Integer>> getMountainColorNum() {
        return mountainColorNum;
    }

    public void setMountainColorNum(List<List<Integer>> mountainColorNum) {
        this.mountainColorNum = mountainColorNum;
    }

    public List<List<Integer>> getMountainDrawNum() {
        return mountainDrawNum;
    }

    public void setMountainDrawNum(List<List<Integer>> mountainDrawNum) {
        this.mountainDrawNum = mountainDrawNum;
    }

    public int getMountainDrawNumByRound(int round) {
        int ret = 1;
        for (List<Integer> list : mountainDrawNum) {
            if (list == null || list.isEmpty() || list.size() < 2) {
                continue;
            }
            if (round >= list.get(0)) {
                ret = list.get(1);
            }
        }
        return ret;
    }
}
